// packageA/pages/kaihei/kaihei.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    ggid:'',
    gglist:'',
    page_no:1
  },
  fuzhi1(e){
    let _this = this
    wx.setClipboardData({
      data: e.currentTarget.dataset.tj_num,
      success (res) {
        wx.getClipboardData({
          success (res) {
            console.log(res.data) // data
            // wx.showToast({
            //   title: '复制成功',
            //   icon: 'success',
            //   duration: 2000
            // })
          }
        })
      }
    })
  },
  z_shezhi(e){
    let params = {
      "token":wx.getStorageSync("user_token"),
      "id":e.currentTarget.dataset.id
    }
    wx.request({
      url: app.apiurl + 'api/member/setHomeInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        wx.showToast({
          title: res.data.msg,
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  z_del(e){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
      "id":e.currentTarget.dataset.id
    }
    wx.showModal({
      title: '删除主页确认',
      content: '您确定要删除这个主页吗？',
      confirmColor:"#FFA61A",
      success (res) {
        if (res.confirm) {
          wx.request({
            url: app.apiurl + 'api/member/homePageDel',
            method: 'POST',
            data: params,
            header: {
              'content-type': 'application/x-www-form-urlencoded' // 修改请求
            },
            success(res) {
               wx.showToast({
                title: res.data.msg,
                icon: 'none',
                duration: 2000
              })
                _this.setData({
                  list:''
                })
                _this.z_jilu()
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      other_member_id:options.id
    })  
    if (wx.getStorageSync("user_token") == "") {
      this.z_dengluyanzeng()
    }
  },
  z_dengluyanzeng(){
    wx.request({
      url: app.apiurl + 'api/home/xcxLoginStatus',
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.code == '1001') {
          if (res.data.data.is_force_login == '1') {
            // wx.reLaunch({
            //   url: '/pages/login/login'
            // });
            wx.showToast({
              title: '请注册/登录会员账号',
              icon: 'none',
              duration: 2000
            })
            setTimeout(function(){
              wx.reLaunch({
                url: '/pages/member/member',
              })
            },2500)
          }
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.guanggao1()
    this.z_jilu()
    this.z_yonghu()
  },
  z_yonghu() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log('111',res)
        if (res.data.code == '1001') {
          let tmp_khgjs_pm = '0';
          if (res.data.data.khgjs_pm > 10) {
            tmp_khgjs_pm = '10+'
          } else {
            tmp_khgjs_pm = res.data.data.khgjs_pm
          }
          _this.setData({
            login: true,
            yonghu: res.data.data,
            khgjs_pm_index: tmp_khgjs_pm
          })
        }
      }
    })
  },
  guanggao1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
         _this.guanggao2()
      }
    })
  },
  guanggao2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=16',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist:res.data.data[0]
         })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  z_jilu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/homePageListNew?page_no=' + _this.data.page_no + '&page_num=100&other_member_id=' + _this.data.other_member_id,
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list:res.data.data.list
         })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    // let _this = this
    // let page_no  = _this.data.page_no
    // page_no = page_no+1
    // _this.setData({
    //   page_no:page_no
    // })
    // _this.z_jilu()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})